package bamboo.drawingkid.controls;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;

import bamboo.drawingkid.Main;
import bamboo.drawingkid.views.MmsEmailView;

public class MmsEmailViewController extends MmsEmailView {

	private static MmsEmailViewController 		self;
	private final Main					midlet;
    private Alert 						alertQuit;

    private Command						cmdQuitAlertYes;
    private Command						cmdQuitAlertNo;

    public static MmsEmailView getInstance()
    {
    	if(self == null){
    		self = new MmsEmailViewController();
    	}
    	return self;
    }

	private MmsEmailViewController() {
		super("");
		midlet = Main.getInstance();
		
    	alertQuit = new Alert("Quit", "Do you really want to quit?", null, AlertType.CONFIRMATION);
    	alertQuit.setTimeout(Alert.FOREVER);
    	alertQuit.addCommand(cmdQuitAlertYes = new Command("Yes", Command.OK, 1));
    	alertQuit.addCommand(cmdQuitAlertNo = new Command("No", Command.CANCEL, 2));
    	alertQuit.setCommandListener(this);
	}

	public void commandAction(Command command, Displayable displayable) {
		if(command == backCommand) {
			midlet.showDrawing();
		} else if (command == exitCommand) {
			midlet.getDisplay().setCurrent(alertQuit);
		} else if (command == cmdQuitAlertYes) {
			midlet.notifyDestroyed();
		} else if (command == cmdQuitAlertNo) {
			midlet.showMmsEmailView();
		} 
	}

}
